<?php


namespace app\common\model;


use think\model;

class Subject extends Model
{
    //  连接数据库
    protected $connection = 'mysql';
    //  连接表名
    protected $name = 'subject';
    //  自动写入时间戳字段
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    // 分页查询,获取列表
    public function fetchListByWhere($where, $order = ['id' => 'desc'], $field = '*', $page = 1, $pageSize = 10)
    {
        return $this->field($field)->where($where)->order($order)->page($page, $pageSize)->select()->toArray();
    }

    //关联题型
    public function types()
    {
        return $this->hasOne(Types::class,'id','types_id')
            ->field('id,name');
    }

    //关联题型程度
    public function degree()
    {
        return $this->hasOne(Degree::class,'id','degree_id')
            ->field('id,title');
    }

    //关联学校专业
    public function major()
    {
        return $this->hasOne(Major::class,'id','major_id')
            ->field('id,name');
    }

    //关联学校年级
    public function grade()
    {
        return $this->hasOne(Grade::class,'id','grade_id')
            ->field('id,name');
    }

    //关联学校
    public function school()
    {
        return $this->hasOne(School::class,'id','school_id')
            ->field('id,name');
    }
}